package com.ruoyi.bpm.controller.admin.definition;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.bpm.controller.admin.definition.vo.expression.BpmProcessExpressionPageReqVO;
import com.ruoyi.bpm.controller.admin.definition.vo.expression.BpmProcessExpressionRespVO;
import com.ruoyi.bpm.controller.admin.definition.vo.expression.BpmProcessExpressionSaveReqVO;
import com.ruoyi.bpm.domain.definition.BpmProcessExpression;
import com.ruoyi.bpm.service.definition.BpmProcessExpressionService;
import com.ruoyi.bpm.utils.BeanUtils;
import com.ruoyi.common.core.core.domain.R;
import com.ruoyi.common.orm.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "管理后台 - BPM 流程表达式")
@RestController
@RequestMapping("/bpm/process-expression")
@Validated
public class BpmProcessExpressionController {

    @Resource
    private BpmProcessExpressionService processExpressionService;

    @PostMapping("/create")
    @Operation(summary = "创建流程表达式")
    @SaCheckPermission("bpm:process-expression:create")
    public R<Long> createProcessExpression(@Valid @RequestBody BpmProcessExpressionSaveReqVO createReqVO) {
        return R.ok(processExpressionService.createProcessExpression(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新流程表达式")
    @SaCheckPermission("bpm:process-expression:update")
    public R<Boolean> updateProcessExpression(@Valid @RequestBody BpmProcessExpressionSaveReqVO updateReqVO) {
        processExpressionService.updateProcessExpression(updateReqVO);
        return R.ok(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除流程表达式")
    @Parameter(name = "id", description = "编号", required = true)
    @SaCheckPermission("bpm:process-expression:delete")
    public R<Boolean> deleteProcessExpression(@RequestParam("id") Long id) {
        processExpressionService.deleteProcessExpression(id);
        return R.ok(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得流程表达式")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @SaCheckPermission("bpm:process-expression:query")
    public R<BpmProcessExpressionRespVO> getProcessExpression(@RequestParam("id") Long id) {
        BpmProcessExpression processExpression = processExpressionService.getProcessExpression(id);
        return R.ok(BeanUtils.toBean(processExpression, BpmProcessExpressionRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得流程表达式分页")
    @SaCheckPermission("bpm:process-expression:query")
    public R<TableDataInfo<BpmProcessExpressionRespVO>> getProcessExpressionPage(
            @Valid BpmProcessExpressionPageReqVO pageReqVO) {
        TableDataInfo<BpmProcessExpression> pageResult = processExpressionService.getProcessExpressionPage(pageReqVO);
        return R.ok(BeanUtils.toBean(pageResult, BpmProcessExpressionRespVO.class));
    }

}
